package App.Controller;

import App.Model.*;
import App.Model.Project.ProjectSaveRequest;
import App.Service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * Created by xw on 2018/11/21.
 */

@RestController
@RequestMapping("/api/member/")
public class MemberController extends BaseController {

    @Autowired
    private ProjectService _service;

    //注册用户
    @RequestMapping("save")
    public ResponseEntity<BaseResponse> register(@RequestBody(required = false) ProjectSaveRequest _request) throws Exception {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        Map<String,Object> result = _service.saveProject(_request, userId());
        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
        int count = (int) result.get("result");
        if ( count > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());

        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

/*
    @RequestMapping("list")
    public ResponseEntity<?> select() {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<ProjectList> _result = _service.getProjectlist(userId(),"");
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }
*/

}
